package com.gilgamesh.mall.product.sql;

import com.gilgamesh.mall.sdk.bean.product.ShopEntity;
import com.gilgamesh.mall.sdk.util.BeanUtil;
import com.gilgamesh.mall.sdk.util.StringUtil;

/**
 * Created by Peiyao.Wang on 2021/1/13
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */

public class ShopSql {
    public  String listShops(ShopEntity shopEntity){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_shop");
        if(BeanUtil.isLogicalNull(shopEntity)){
            return sb.toString();
        }
        int times = 0;
        if(StringUtil.isNotEmpty(shopEntity.getShopName())){
            if(times == 0){
                sb.append("where");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("shop_name = #{shop_name}");
        }
        if(shopEntity.getCreateTime() != null){
            if(times == 0){
                sb.append("where");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("create_time =#{createTime}");
        }
        if(StringUtil.isNotEmpty(shopEntity.getShopCode())){
            if(times == 0){
                sb.append("where");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("shop_code = #{shopCode}");
        }
        return sb.toString();
    }

}
